package com.xiaoma.threadlocal;

/**
 * @author xiaomacdut
 * @date 2020年2月15日 下午12:22:03
 */
public class ThreadLocalDemo{
    
   public static ThreadLocal<String> stringLocal = new ThreadLocal<String>();

   public static ThreadLocal<String> local = new ThreadLocal<String>();


    public static void main(String [] args) throws InterruptedException{
        final ThreadLocalDemo test = new ThreadLocalDemo();
        stringLocal.set("aa");
        local.set("aa1");
        System.out.println("0:" + stringLocal.get());

        Thread thread = new Thread(){
            
            public void run(){
                stringLocal.set("bb");
                System.out.println("1:" + stringLocal.get());
            };
        };
        
        thread.start();
        thread.join();// main线程等到其他多个线程执行完毕后再继续执行

        System.out.println("2:" + stringLocal.get());//这里是主线程，能取到set的值 “aa”
        
    }
}
